﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class User_Address_ListController : UserController
    {
        public IUser_addr_bookService _user_addr_book { get; set; }
        [Authorize]
        [HttpGet]
        public IActionResult Get()
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                return Ok(new { status = 0, msg = "用户尚未登录或已超时!" });
            }
            var list = _user_addr_book.GetList("where user_id=" + userModel.id);
            if (list.Count > 0)
            {
                return Ok(new { status = 1, list = list});
            }
            else
            {
                return Ok(new { status = 0, msg = "收货地址不存在！" });
            }
        }
    }
}